package com.justech.mes.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间计算工具类
 * 1.休息时间计算
 *
 * @author feifei.li
 */
public class RestTimeCalcuUtil {
    /**
     * 将休息时间转换为double类型
     *
     * @param time
     * @return
     */
    public static double conventTimeToDouble(String time) {
        String colons = ":";
        if (time == null || time.length() == 0 || time.indexOf(colons) == -1) {
            throw new RuntimeException("time为空或者格式不正确");
        }
        String[] arr = time.split(":");
        return Double.valueOf(Integer.valueOf(arr[0]) + "." + arr[1]);
    }

    /**
     * 将数字转换成毫秒
     *
     * @param d
     * @return
     */
    public static Long formatStamp(double d) {
        long res = (long) d * (1000 * 60 * 60);
        return res;
    }

    /**
     * 将时间转换成时间戳
     *
     * @param timeString
     * @return
     */
    public static Long formatStamp(String timeString) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        try {
            Date parse = sdf.parse(timeString);
            return parse.getTime();
        } catch (ParseException e) {
        }
        return 0L;
    }

    public static void main(String[] args) {
        RestTimeCalcuUtil.conventTimeToDouble("");
    }

}
